package com.ruoyi.web.controller.wnjk.hospital;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.wnjk.domain.po.WnjkRegistrationOrder;
import com.ruoyi.system.wnjk.service.IWnjkRegistrationOrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 挂号订单Controller
 *
 * @author ruoyi
 * @date 2025-03-16
 */
@Slf4j
@RestController
@RequestMapping("/system/order")
public class WnjkRegistrationOrderController extends BaseController
{
    @Autowired
    private IWnjkRegistrationOrderService wnjkRegistrationOrderService;

    /**
     * 查询挂号订单列表
     */
    @PreAuthorize("@ss.hasPermi('system:order:list')")
    @GetMapping("/list")
    public TableDataInfo list(WnjkRegistrationOrder wnjkRegistrationOrder)
    {
        startPage();
        List<WnjkRegistrationOrder> list = wnjkRegistrationOrderService.selectWnjkRegistrationOrderList(wnjkRegistrationOrder);
        return getDataTable(list);
    }

    /**
     * 导出挂号订单列表
     */
    @PreAuthorize("@ss.hasPermi('system:order:export')")
    @Log(title = "挂号订单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WnjkRegistrationOrder wnjkRegistrationOrder)
    {
        List<WnjkRegistrationOrder> list = wnjkRegistrationOrderService.selectWnjkRegistrationOrderList(wnjkRegistrationOrder);
        ExcelUtil<WnjkRegistrationOrder> util = new ExcelUtil<WnjkRegistrationOrder>(WnjkRegistrationOrder.class);
        util.exportExcel(response, list, "挂号订单数据");
    }

    /**
     * 获取挂号订单详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:order:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(wnjkRegistrationOrderService.selectWnjkRegistrationOrderById(id));
    }

    /**
     * 新增挂号订单
     */
    @PreAuthorize("@ss.hasPermi('system:order:add')")
    @Log(title = "挂号订单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody WnjkRegistrationOrder wnjkRegistrationOrder)
    {
        return toAjax(wnjkRegistrationOrderService.insertWnjkRegistrationOrder(wnjkRegistrationOrder));
    }

    /**
     * 修改挂号订单
     */
    @PreAuthorize("@ss.hasPermi('system:order:edit')")
    @Log(title = "挂号订单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WnjkRegistrationOrder wnjkRegistrationOrder)
    {
        return toAjax(wnjkRegistrationOrderService.updateWnjkRegistrationOrder(wnjkRegistrationOrder));
    }

    /**
     * 删除挂号订单
     */
    @PreAuthorize("@ss.hasPermi('system:order:remove')")
    @Log(title = "挂号订单", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(wnjkRegistrationOrderService.deleteWnjkRegistrationOrderByIds(ids));
    }
}
